package com.hudongwx.food.activity;

import android.content.Intent;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.ProgressBar;

import com.hudongwx.food.R;
import com.hudongwx.food.tiaozhuan_fragment.HaoGuoFragment;
import com.hudongwx.food.tiaozhuan_fragment.HaoJiaFragment;
import com.hudongwx.food.tiaozhuan_fragment.HaoJiangFragment;
import com.hudongwx.food.tiaozhuan_fragment.HaoJiuFragment;
import com.hudongwx.food.tiaozhuan_fragment.HaoMianFragment;
import com.hudongwx.food.tiaozhuan_fragment.HaoYouFragment;

/**
 * 首页跳转
 */
public class ShouYeTiaoZhuanActivity extends AppCompatActivity {
private HaoYouFragment haoYouFragment;
    private HaoMianFragment haoMianFragment;
    private HaoGuoFragment haoGuoFragment;
    private HaoJiangFragment haoJiangFragment;
    private HaoJiuFragment haoJiuFragment;
    private HaoJiaFragment haoJiaFragment;
    private TabLayout tabLayout;
    private ViewPager viewPager;
    private ImageView imageView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_shou_ye_tiao_zhuan);
        tabLayout = (TabLayout) findViewById(R.id.tiaozhuan_tablayout);
        viewPager = (ViewPager) findViewById(R.id.tiaozhuan_viewpager);
        imageView = (ImageView) findViewById(R.id.tiaozhuan_img);
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        Myadapter myadapter = new Myadapter(getSupportFragmentManager());
        viewPager.setAdapter(myadapter);
        tabLayout.setupWithViewPager(viewPager);
        //跳转是点击哪个条哪个
        Intent intent = getIntent();
        int type = intent.getIntExtra("type", 0);
        viewPager.setCurrentItem(type);
    }
    class Myadapter extends FragmentStatePagerAdapter {
        public Myadapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            switch (position) {
                case 0:
                    if (haoYouFragment == null) {
                        haoYouFragment = new HaoYouFragment();
                    }
                    return haoYouFragment;
                case 1:
                    if (haoMianFragment == null) {
                        haoMianFragment = new HaoMianFragment();
                    }
                    return haoMianFragment;
                case 2:
                    if (haoGuoFragment == null) {
                        haoGuoFragment = new HaoGuoFragment();
                    }
                    return haoGuoFragment;
                case 3:
                    if (haoJiangFragment == null) {
                        haoJiangFragment = new HaoJiangFragment();
                    }
                    return haoJiangFragment;
                case 4:
                    if (haoJiuFragment == null) {
                        haoJiuFragment = new HaoJiuFragment();
                    }
                    return haoJiuFragment;
                case 5:
                    if (haoJiaFragment == null) {
                        haoJiaFragment = new HaoJiaFragment();
                    }
                    return haoJiaFragment;
                default:
                    return null;
            }
        }

        @Override
        public int getCount() {
            return 6;
        }
        @Override
        public CharSequence getPageTitle(int position) {
            switch (position){
                case 0:
                    return "好油";
                case 1:
                    return "好面";
                case 2:
                    return "好果";
                case 3:
                    return "好浆";
                case 4:
                    return "好酒";
                case 5:
                    return "好酱";
                default:
                    return null;
            }
        }
    }
}
